package com.myteam.mystory.service;

import java.util.ArrayList;
import java.util.List;

import com.myteam.mystory.DAO.CategoriesDAO;
import com.myteam.mystory.DAO.CreateDatabase;
import com.myteam.mystory.entity.CategoryEntity;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class CategoriesService {
	private Context context;

	public CategoriesService(Context context) {
		super();
		this.context = context;
	}
	public long insert_categories(CategoryEntity categoryEntity){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		CategoriesDAO categoriesDAO = new CategoriesDAO(db);
		long result = categoriesDAO.insert_categories(categoryEntity);
		db.close();
		createDb.close();
		return result;
	}
	
	public ArrayList<CategoryEntity> getAllCategories() {
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		CategoriesDAO categoriesDAO = new CategoriesDAO(db);
		ArrayList<CategoryEntity> list_cate = new ArrayList<CategoryEntity>();
		list_cate = categoriesDAO.getAllCategories();
		db.close();
		createDb.close();
		return list_cate;
	}
	
	public List<String> getCateName(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		CategoriesDAO categoriesDAO = new CategoriesDAO(db);
		List<String> arr_cateName = new ArrayList<String>();
		arr_cateName = categoriesDAO.getCateName();
		db.close();
		createDb.close();
		return arr_cateName;
	}
	
	public long deleteTableCategory(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		CategoriesDAO categoriesDAO = new CategoriesDAO(db);
		long result = categoriesDAO.deleteCategoryTable();
		db.close();
		createDb.close();
		return result;
	}
}
